<?php
require_once 'inc/configuration.php';
require_once 'inc/connexion_db.php';
require_once 'inc/fonctions_identification.php';

session_start();

if(isset($_POST["action"])) {
    $action = $_POST["action"];
}
else if(isset($_GET["action"])) {
    $action = $_GET["action"];
}
else {
    $action = "";
}

if($action==1) {
//    echo "coucou";
    $login = isset($_POST["login"]) ? $_POST["login"] : "";
    $mot_passe = isset($_POST["mot_passe"]) ? $_POST["mot_passe"] : ""; 
    
    $message_action = identifier_utilisateur($login, $mot_passe);   
}
else if($action==2) {
    deconnexion();
}

if(isset($_GET["message_action"])) $message_action = unserialize($_GET["message_action"]);

$utilisateur_id = isset($_SESSION["utilisateur_id"]) ? $_SESSION["utilisateur_id"] : "";
?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="ISO-8859-1">
        <title>CARNET D'ADRESSES - ENTREPRISES > ACCUEIL</title>
        
        <?php require_once "inc/css_js_bootstrap/css_js_bootstrap.php"; ?>
        
        <style>
            #zone_identification {
                width: 300px;
                background-color: #CCC;
                margin-left: auto;
                margin-right: auto;
                border: 2px #FFF solid;
                border-radius: 20px;
                padding:25px;
                box-shadow: 0px 0px 10px #6699ff;
                text-align: center;
            }
            #zone_identification input[type="text"], input[type="password"] {
                text-align: center;
            }
        </style>
    </head>
    <body>
        <?php require_once "inc/menus/menu_principal.php"; ?>
        <h1>PAGE D'ACCUEIL</h1>
        
        <?php if(!empty($message_action)) { ?>
            <div id="message_action" class="alert <?php echo $message_action["css_class"]; ?>"><?php echo $message_action["texte"]; ?></div>
        <?php } ?>
            
        <?php 
        if(empty($utilisateur_id)) {
        ?>
        <div id="zone_identification">
        <form name="identification" id="identification" method="post">
              <div class="form-group">
                <label for="login">Login</label>
                <input type="text" class="form-control" name="login" id="login" placeholder="Saisissez votre login" required>
              </div>
              <div class="form-group">
                <label for="exampleInputPassword1">Password</label>
                <input type="password" class="form-control" name="mot_passe" id="mot_passe" placeholder="Saisissez votre mot de passe" required>
              </div>
            <button type="submit" name="action" value="1" class="btn btn-success"><span class="glyphicon glyphicon-ok"></span> Envoyer</button>
        </form>      
        </div>
        <?php
        }
        ?>
    </body>
</html>
